﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using ZHDJ.Data.Models.Common;
using ZHDJ.Data.Models.Org;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.BranchHome
{
    public partial class BranchMember : UseMorePageMasterPage
    {
        /// <summary>
        /// BranchID
        /// </summary>
        private string BranchID
        {
            get
            {
                return this.Request["BranchID"] ?? "null";
            }
        }
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }

        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
                return;
            }
            else if (!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();
                return;
            }
            if (!IsPostBack)
            {
                LoadData();
            }

        }
        public void LoadData()
        {
            hdBranchID.Value = BranchID;
        }

        private void WriteList()
        {
            DataTable dt = PartyOrgMember.GetMemberByBranchId(BranchID,"",Convert.ToInt32(this.PageIndex), Convert.ToInt32(PageSize),0).Tables[0];

            dt.Columns.Add("ImgUrl", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["ImgUrl"] = UpFileBusiness.GetFileUrl(Convert.ToString(dr["ImageUrl"]));
                dr["IdentityCard"] = "";
                dr["MobileNo"] = "";
            }
            var json = JsonConvert.SerializeObject(dt);
            Response.Clear();
            Response.Write(json);
            Response.End();
        }
        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(DB.PartyOrgMembers.Count(a=>a.runSate=="0" && a.BranchID==BranchID));
            Response.End();
        }
        #region 模块菜单
        /// <summary>
        /// 初始化module  如果通过url传参可不设置
        /// </summary>
        protected override void InitModule()
        {
            Module = "BranchHomeMore";
            Category = "BranchMember";

        }
        #endregion
    }
}